package com.sky.controller.admin;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品表现层
 */
@RestController("adminDishController")
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;
    /**
     * 新增菜品
     * @param dto
     * @return
     */
    @PostMapping
    public Result addDish(@RequestBody DishDTO dto){
        return dishService.addDish(dto);
    }

    /**
     * 查询菜品管理
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public Result pageDish(DishPageQueryDTO dto){
        return dishService.pageDish(dto);
    }

    /**
     * 删除菜品以及批量删除
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deleteDish(@RequestParam List<Long> ids){
        return dishService.deleteDish(ids);
    }

    /**
     * 单一查询菜品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<DishVO> getById(@PathVariable Long id){
        return dishService.getById(id);
    }

    /**
     * 修改菜品
     * @param dto
     * @return
     */
    @PutMapping
    public Result updateDish(@RequestBody DishDTO dto){
        return dishService.updateDish(dto);
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<Dish>> list(Long categoryId){
        List<Dish> list = dishService.list(categoryId);
        return Result.success(list);
    }
}
